package com.gopay.checkorder.service.task.thread.batch;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;

import com.gopay.gass.message.GassBcdlNotifyRespMessage;
import com.gopay.gass.service.GassPayRemoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.checkorder.service.BankOrderService;
import com.gopay.checkorder.service.alarm.OrderAlarmDataCollector;
import com.gopay.common.constants.bank.BankOrderStatus;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.domain.bank.BcdlResult;
import com.gopay.common.domain.cps.vo.CheckOrderResult;
import com.gopay.common.util.HttpTransport;

import javax.annotation.Resource;

/**
 * 
 * @author lizheng
 *
 */
public class BcdlResultDeal4BatchThread implements Runnable {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	private GassPayRemoteService gassPayService;
	//private CountDownLatch latch;
	private BcdlResult bcdlResult;
	private String notifyGassUrl;

	public BcdlResultDeal4BatchThread(BcdlResult bcdlResult,GassPayRemoteService gassPayService) {
		this.bcdlResult = bcdlResult;
		this.gassPayService = gassPayService;
	}

	@Override
	public void run() {
		try {
			/*HttpTransport notifyGass = new HttpTransport();
			notifyGass.setSendEncoding("UTF-8");*/  //生产优化10期修改前 使用httpclient lx 2017-9-29 15:46:09
			Map<String, String> param = new HashMap<String, String>();
			if (ProcCodeConstants.PROC_CODE_100E6027.equals(bcdlResult.getResultCode())) {
				param.put("resultCode", "2");
				param.put("resultMsg", bcdlResult.getErrorMsg());
				//delete by zyt,2017-8-4，删除remark标志
				// param.put("remark", "1");
				if(bcdlResult.isNeedRefund()){
					param.put("needRefund", "1");
				}
				param.put("gopayOrderId", bcdlResult.getGopayOrderId());
				/*notifyGass.setUrl(notifyGassUrl);
				notifyGass.submit(param);*/ //生产优化10期修改前 使用httpclient lx 2017-9-29 15:46:09

			} else if (ProcCodeConstants.PROC_CODE_100S1000.equals(bcdlResult.getResultCode())) {
				param.put("resultCode", "1");
				//delete by zyt,2017-8-4，删除remark标志
				// param.put("remark", "1");
				param.put("gopayOrderId", bcdlResult.getGopayOrderId());
				/*notifyGass.setUrl(notifyGassUrl);
				notifyGass.submit(param);*/ //生产优化10期修改前 使用httpclient lx 2017-9-29 15:46:09
				// }else
				// if(ProcCodeConstants.PROC_CODE_100E6047.equals(result.getResultCode())
				// ){
				// logger.error("label_"+label+"银企直连 超时休眠--开始 ，orderId="+bankOrder.getOrderId()+",bank="+bank);
				// Thread.sleep(5000);
				// logger.error("label_"+label+"银企直连 超时休眠--结束 ，orderId="+bankOrder.getOrderId()+",bank="+bank);
			} else {
				param.put("resultCode", "3");
				//delete by zyt,2017-8-4，删除remark标志
				// param.put("remark", "1");
				param.put("gopayOrderId", bcdlResult.getGopayOrderId());
				/*notifyGass.setUrl(notifyGassUrl);
				notifyGass.submit(param);*/ //生产优化10期修改前 使用httpclient lx 2017-9-29 15:46:09
			}

			GassBcdlNotifyRespMessage respMessage = gassPayService.bcdlNotifyGass(param); //生产优化10期修改后 使用hession lx 2017-9-29 15:46:09
			logger.error("Checkoder Hsession 调用bis返回响应码 : " + respMessage.getResultCode() + ",gopayOrderId:" + bcdlResult.getGopayOrderId());

		} catch (Exception e) {
			logger.info("---------- 对单error---------", e);
		} finally {
			//latch.countDown();
		}
	}
}
